precision highp float;

uniform sampler2D u_tex;
uniform vec2 u_screen_size;
uniform vec2 u_center;
uniform float u_radius;
uniform float u_core;

varying vec2 v_uv;

const vec4 F = vec4(0.25, 0.5, 0.75, 1.0);
const vec4 W = vec4(0.14489292176612587, 0.12264921034103102, 0.09290249985875561, 0.06297020422491453);


vec4 texture2Dclamp (sampler2D tex, vec2 uv) {
	vec4 color = texture2D(tex, uv);
	uv = step(vec2(0.0), uv) * step(uv, vec2(1.0));
	return color * uv[0] * uv[1];
}

void main () {
	vec2 rec_screen_size = 1.0 / u_screen_size;
	vec2 o = u_center;
	vec2 p = v_uv * u_screen_size;
	vec2 v = normalize(p - o);
	vec2 s = v * rec_screen_size * (u_radius * smoothstep(0.0, u_core, length(p - o)));

	vec4 sum = texture2D(u_tex, v_uv) * 0.133571;
	for (int i = 0; i < 4; ++i) {
		sum += texture2Dclamp(u_tex, v_uv + s * F[i]) * W[i];
		sum += texture2Dclamp(u_tex, v_uv - s * F[i]) * W[i];
	}
	gl_FragColor = sum;
}